package com.foolishbird.sdk.ui.fragment;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.foolishbird.sdk.core.HttpEngineApi;
import com.foolishbird.sdk.params.FloatGiftReciveResponseParams;
import com.foolishbird.sdk.params.RedWechatResponseParams;
import com.foolishbird.sdk.params.ResponseParams;
import com.foolishbird.sdk.params.bean.RedBindedInfo;
import com.foolishbird.sdk.params.bean.State;
import com.foolishbird.sdk.utils.MyFragmentManger;
import com.foolishbird.sdk.utils.ResUtils;
import com.foolishbird.sdk.utils.WL;

import java.util.List;


public class RedpackageTixianNowFragment extends BaseHttpFragment implements View.OnClickListener {



    private TextView titleTxt;

    private ImageView backView;
    TextView moneyText;
    private Button confirmBtn;

    public static final RedpackageTixianNowFragment newInstance(Bundle bundle) {
        RedpackageTixianNowFragment fragment = new RedpackageTixianNowFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    private int type;
    private String money;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        int resource = ResUtils.getLayoutIdentifier(getActivity(), "fb_redpackage_tixiannow");
        View contentView =inflater.inflate(resource,null);
        type = getArguments().getInt("type");
        money = getArguments().getString("money");
        backView = contentView.findViewById(getViewIdentifier("fb_fragment_login_back"));
        backView.setOnClickListener(this);
        titleTxt = contentView.findViewById(getViewIdentifier("fb_fragment_float_title"));
        titleTxt.setText(type==1?"提现至微信":"提现至支付宝");
        moneyText = contentView.findViewById(getViewIdentifier("redpackage_tixiannow_money"));
        moneyText.setText(money);
        confirmBtn = contentView.findViewById(getViewIdentifier("redpackage_tixiannow_confirm"));
        confirmBtn.setOnClickListener(this);
//        HttpEngineApi.getInstance().redpackageCommon("wx_bind",requestCallbackHandler(RedWechatResponseParams.class));
        return contentView;

    }

    private List<RedBindedInfo> myNoticeList;

    @Override
    public void onAsyncRequestResult(int flag, ResponseParams response, Object... params) {
        super.onAsyncRequestResult(flag, response, params);
        if (response != null) {
            int code = response.getState().getCode();
            if (State.SUCCESS == code) {
                if(flag==TaskId){
                   Toast.makeText(getContext(),"提现申请提交成功",Toast.LENGTH_SHORT).show();
                   MyFragmentManger.getInstance().goBack(this);
                }
            }else{
                if(flag==TaskId){
                    Toast.makeText(getContext(),response.getState().getMsg(),Toast.LENGTH_SHORT).show();

                }
            }
        }



        WL.d("FloatNoticeFragment",response.toString());
    }

    public static  int TaskId;





    @Override
    public void onClick(View view) {
        if(view ==backView){
            MyFragmentManger.getInstance().goBack(this,true);
        }else if(view == confirmBtn){
            TaskId =HttpEngineApi.getInstance().redpackageTixian(money,type+"",requestCallbackHandler(FloatGiftReciveResponseParams.class));
        }
//        OnFinishActivityListener listener = getOnFinishActivityListener();
//        if (listener != null) {
//            listener.doFinishActivity(this);
//        }
    }


}
